package pers.rcl.utils;

import java.security.MessageDigest;

public class MD5 {
	public static String md5(String type, String str) {
		try {
			String result = "";
			MessageDigest md = MessageDigest.getInstance(type);
			byte[] bytes = md.digest(str.getBytes("UTF-8"));
			for (byte b : bytes) {
				String hex = Integer.toHexString(b & 0xFF).toUpperCase();
				result += ((hex.length() == 1) ? "0" : "") + hex;
			}
			return result;
		} catch (Exception e) {
			throw new RuntimeException(e);
		}
	}

	/**
	 * MD5加密
	 * 
	 * @param str
	 * @return
	 */
	public static String getMd5(String str) {
		return md5("MD5", str);
	}

}
